package com.fucking.great.context.util;

import cn.hutool.core.getter.OptNullBasicTypeFromObjectGetter;
import cn.hutool.core.map.MapWrapper;

import java.util.Map;

/**
 * getMap装饰. <br/>
 * Map代理，提供各种getXXX方法，并提供默认值支持 <br/>
 * @see cn.hutool.core.getter.OptNullBasicTypeFromObjectGetter
 * @param <K>
 * @param <V>
 */
public class GetMapDecorator<K, V> extends MapWrapper<K, V> implements OptNullBasicTypeFromObjectGetter<K> {
    /**
     * 构造
     *
     * @param raw 被包装的Map
     */
    public GetMapDecorator(Map<K, V> raw) {
        super(raw);
    }

    @Override
    public Object getObj(K key, Object defaultValue) {
        return this.get(key);
    }
    /**
     * a,b,c => [a,b,c]
     * @param key
     * @return
     */
    public String[] getStrArray(K key){
        return getStrArray(key,",");
    }
    /**
     * a,b,c => [a,b,c]
     * @param key
     * @param split
     * @return
     */
    public String[] getStrArray(K key,String split){
        String str = this.getStr(key, "");
        String[] splits = str.split(split);
        return splits;
    }
}
